package com.aaa.service.impl;

import com.aaa.entity.QuestionSas;
import com.aaa.dao.QuestionSasDao;
import com.aaa.service.QuestionSasService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;
import java.util.List;

/**
 * 问题表(QuestionSas)表服务实现类
 *
 * @author
 * @since 2022-07-06 11:56:31
 */
@Service("questionSasService")
public class QuestionSasServiceImpl implements QuestionSasService {
    @Resource
    private QuestionSasDao questionSasDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public QuestionSas queryById(Integer id) {
        return this.questionSasDao.queryById(id);
    }

    /**
     * 分页查询
     *
     * @param questionSas 筛选条件
     * @param pageRequest 分页对象
     * @return 查询结果
     */
    @Override
    public Page<QuestionSas> queryByPage(QuestionSas questionSas, PageRequest pageRequest) {
        long total = this.questionSasDao.count(questionSas);
        return new PageImpl<>(this.questionSasDao.queryAllByLimit(questionSas, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param questionSas 实例对象
     * @return 实例对象
     */
    @Override
    public QuestionSas insert(QuestionSas questionSas) {
        this.questionSasDao.insert(questionSas);
        return questionSas;
    }

    /**
     * 修改数据
     *
     * @param questionSas 实例对象
     * @return 实例对象
     */
    @Override
    public boolean update(QuestionSas questionSas) {
        int update = this.questionSasDao.update(questionSas);
        if (update > 0) {
            return true;
        }
        return false;
    }

    /**
     * 通过主键删除数据
     *
     * @param idList 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(String idList) {
        return this.questionSasDao.deleteById(idList) > 0;
    }

    /**
     * @param questionSas
     * @return boolean
     * @create by: feng (zhaixing@163.com)
     * @description: 唯一性校验
     * @create time: 2022/7/15 17:18
     */
    @Override
    public boolean repetitionName(QuestionSas questionSas) {
        Integer integer = this.questionSasDao.repetitionName(questionSas);
        if (integer == 0) {
            return true;
        }
        return false;
    }

    @Override
    public List<QuestionSas> findAllQuestion() {
        return questionSasDao.findAllQuestion();
    }
}
